package it.gat.mobile.utils;

import it.gat.controller.utils.Impostazioni;
import it.gat.controller.utils.WSImpostazioni;
import android.content.Context;
import android.content.SharedPreferences;

public class ImpostazioniAndroid implements Impostazioni{

	private SharedPreferences prefs;

	public ImpostazioniAndroid(Context context)
	{
		prefs = context.getSharedPreferences("GatPreferences", Context.MODE_PRIVATE);
		String name = prefs.getString("name", null);
		if (name==null)
		{
			getDefault();
			initImpostazioni();
		}
	}

	private void getDefault()
	{
		SharedPreferences.Editor editor = prefs.edit();
		editor.putString(WSImpostazioni.WEBSERVICEURL, "192.168.2.30");
		editor.putString(WSImpostazioni.WEBSERVICEPORT, "8080");
		editor.putString(WSImpostazioni.WEBSERVICEURI, "gat-webservice");
		editor.commit();
	}

	public String getProperty(String key) {
		return prefs.getString(key, null);
	}

	@Override
	public void initImpostazioni() {
		WSImpostazioni.setWebserviceUrl(getProperty(WSImpostazioni.WEBSERVICEURL));
		WSImpostazioni.setWebservicePort(getProperty(WSImpostazioni.WEBSERVICEPORT));
		WSImpostazioni.setWebserviceUri(getProperty(WSImpostazioni.WEBSERVICEURI));

	}





}
